package com.common.service;

import com.common.dao.UserMapper;
import com.common.entity.PageUser;
import com.common.entity.User;
import com.common.entity.UserCorrelationRole;
import com.common.entity.UserRolesAndPermissions;

import java.util.List;

import javax.annotation.Resource;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 14-1-28
 * <p>Version: 1.0
 */
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    private PasswordHelper passwordHelper;

    public void setPasswordHelper(PasswordHelper passwordHelper) {
        this.passwordHelper = passwordHelper;
    }

    @Override
    public User createUser(User user) {  
        passwordHelper.encryptPassword(user);
        userMapper.insertUser(user);
        return user;
    }

    @Override
    public User findUserByName(User user){
    	return userMapper.findUserByName(user);
    }
    
	@Override
	public List<PageUser> getAllUserList() {
		return userMapper.getAllUserList();
	}

	@Override
	public UserRolesAndPermissions getUsersRolesAndPermissions(User user) {
		return userMapper.getUsersRolesAndPermissions(user);
	}

	@Override
	public int correlationRole(UserCorrelationRole userRole) {
		return userMapper.correlationRole(userRole);
	}

	@Override
	public int uncorrelationRole(UserCorrelationRole userRole) {
		return userMapper.uncorrelationRole(userRole);
	}

}
